# Created by Gigiikun
# Update by pmq 17-09-2010
import sys
from com.l2jserver import Config
from com.l2jserver.gameserver.model.quest import State
from com.l2jserver.gameserver.model.quest import QuestState
from com.l2jserver.gameserver.model.quest.jython import QuestJython as JQuest

qn = "642_APowerfulPrimevalCreature"

#Npc
Dinn = 32105
#Settings: drop chance in %
EGG_DROP_CHANCE = 1
TISSUE_DROP_CHANCE = 33

#Set this to non-zero to use 100% recipes as reward instead of default 60%
ALT_RP_100 = 0

DINOSAUR_TISSUE = 8774
DINOSAUR_EGG = 8775
#DINOSAURS = [22196,22197,22198,22199,22200,22201,22202,22203,22204,22205,22218,22219,22220,22223,22224,22225,18344] OLD MOB
DINOSAURS = [22199,22215,22216,22217,22196,22197,22198,22218,22223,18344]
REWARDS = [8690,8692,8694,8696,8698,8700,8702,8704,8706,8708,8710]
REWARDS_W = {
    "1" : [9967 , 1], # 制作卷轴(王朝剑60%)
    "2" : [9968 , 1], # 制作卷轴(王朝之刃60%)
    "3" : [9969 , 1], # 制作卷轴(王朝幻影剑60%)
    "4" : [9970 , 1], # 制作卷轴(王朝弓60%)
    "5" : [9971 , 1], # 制作卷轴(王朝小刀60%)
    "6" : [9972 , 1], # 制作卷轴(王朝长柄战戟60%)
    "7" : [9973 , 1], # 制作卷轴(王朝战锤60%)
    "8" : [9974 , 1], # 制作卷轴(王朝钉锤60%)
    "9" : [9975 , 1], # 制作卷轴(王朝拳套爪60%)
    }
# Dinn Html
# 32105-00
Dinn_A = "<html><body>丁定：<br>哦，您看来不像是适合这危险孤岛的客人耶...这里是非常危险的地方，离开此地对您会有帮助的。<br>(只有达到等级75以上才能执行任务。)</body></html>"
# 32105-01
Dinn_B = "<html><body>丁定：<br>哦，好久没有客人来到这危险的孤岛耶...冒险家阁下也是听到消息来的吧...<br><a action=\"bypass -h Quest 642_APowerfulPrimevalCreature Dinn_C\">您说的是什么消息？</a></body></html>"
# 32105-02
Dinn_C = "<html><body>丁定：<br>这原始之岛是最近才被发现的...不久后查明出，这儿不是一般的岛屿。在其他地方见不到的巨大且强力的生命体生存于此。<br>许多人对有关那全新的生命体感到莫大的兴趣。<br><a action=\"bypass -h Quest 642_APowerfulPrimevalCreature Dinn_D\">询问哪些人们对什么东西感到兴趣</a></body></html>"
# 32105-03
Dinn_D = "<html><body>丁定：<br>满腹学识的魔法师们将那些生命称为恐龙，还说它们不是被目前所知的亚丁诸神创造的生命。<br>现在各地的魔法师都在研究有关恐龙们的起源，以及恐龙出现的意义。<br>此外，各地的工匠对于能否利用这新出现的强力生物来制造新武器或是各种材料的事情，也感到莫大的兴趣。<br><a action=\"bypass -h Quest 642_APowerfulPrimevalCreature Dinn_E\">我想为这些人助一臂之力</a><br><a action=\"bypass -h Quest 642_APowerfulPrimevalCreature Dinn_L\">自己的事应该自己去做，我没兴趣</a></body></html>"
# 32105-04
Dinn_E = "<html><body>丁定：<br>哦，是这样吗？真是太好了。对于恐龙感到莫大兴趣的魔法师们以及矮人工匠们，为了收集他们工作时需要的材料，很想获得冒险家们的帮助。因为这原始之岛是个危险之地。<br>他们还拜托过我，为他们推荐能够接手此事的冒险家呢。<br>去击倒<font color=\"LEVEL\">喙嘴龙、暴龙、迅猛龙</font>后，收集它们的活体组织来吧。<br>对了，将1颗<font color=\"LEVEL\">古代之卵</font>与150个恐龙活体组织组为一套的话，也可透过实验来加工喔。<br>关于古代之卵，只要搜寻恐龙们的栖息地就能找得到。但是非常危险，可要小心喔。触碰古代之卵的话，<font color=\"LEVEL\">周围的恐龙们为了保护古代之卵，全部都会跑来的。古代之卵不像恐龙活体组织一样需要很多，所以请考虑清楚后再做决定吧！</font><br>那么，祝您好运。</body></html>"
# 32105-05
Dinn_F = "<html><body>丁定：<br>许多人正等待着冒险家大人的帮助啦。<br>去击倒<font color=\"LEVEL\">喙嘴龙、暴龙、迅猛龙</font>后，收集它们的活体组织来吧。<br>对了，将1颗<font color=\"LEVEL\">古代之卵</font>与150个恐龙活体组织组为一套的话，也可透过实验来加工喔。<br>只要搜寻恐龙们的栖息地就能找得到古代之卵。但是非常危险，可要小心喔。触碰古代之卵的话，<font color=\"LEVEL\">周围的恐龙们为了保护古代之卵，通通都会跑来的。古代之卵不像恐龙活体组织一样需要很多，所以请考虑清楚后再做决定！</font><br>那么快去收集一些回来吧。</body></html>"
# 32105-06
Dinn_G = "<html><body>丁定：<br>哦~您收集来啦。大家一定会很高兴的。<br><a action=\"bypass -h Quest 642_APowerfulPrimevalCreature Dinn_H\">交出恐龙活体组织</a><br><a action=\"bypass -h Quest 642_APowerfulPrimevalCreature Dinn_I\">将1颗古代之卵和150个恐龙活体组织透过实验加工</a><br><a action=\"bypass -h Quest 642_APowerfulPrimevalCreature Dinn_M\">说想查看其他物品</a></body></html>"
# 32105-06a
Dinn_H = "<html><body>丁定：<br>辛苦了。往后会有许多研究将开始进行。希望能有好成果，如果能有许多人来这原始之岛就好了...这是我小小的心意。请收下...要继续帮忙吗？<br><a action=\"bypass -h Quest 642_APowerfulPrimevalCreature Dinn_K\">说要继续做</a><br><a action=\"bypass -h Quest 642_APowerfulPrimevalCreature Dinn_L\">说要放弃</a></body></html>"
# 32105-07
Dinn_I = "<html><body>丁定：<br>By processing 1 Ancient Egg and 150 dinosaur biological tissues, it's possible to create some truly special materials.<br>These materials will be of great help to the scholars studying these creatures.<br>If you give me the ingredients that you've collected in order to make the processed material, I'll trade you the following items：<br><a action=\"bypass -h Quest 642_APowerfulPrimevalCreature 8690\">制作卷轴(希露冰刃60%)</a><br><a action=\"bypass -h Quest 642_APowerfulPrimevalCreature 8692\">制作卷轴(伊波斯巨剑60%)</a><br><a action=\"bypass -h Quest 642_APowerfulPrimevalCreature 8694\">制作卷轴(贝拉凯尔圣斧60%)</a><br><a action=\"bypass -h Quest 642_APowerfulPrimevalCreature 8696\">制作卷轴(贝希莫斯巨叉60%)</a><br><a action=\"bypass -h Quest 642_APowerfulPrimevalCreature 8698\">制作卷轴(那卡风暴60%)</a><br><a action=\"bypass -h Quest 642_APowerfulPrimevalCreature 8700\">制作卷轴(岱依封长戟60%)</a><br><a action=\"bypass -h Quest 642_APowerfulPrimevalCreature 8702\">制作卷轴(夏伊德猎弓60%)</a><br><a action=\"bypass -h Quest 642_APowerfulPrimevalCreature 8704\">制作卷轴(索贝克飓风60%)</a><br><a action=\"bypass -h Quest 642_APowerfulPrimevalCreature 8706\">制作卷轴(缇米丝之舌60%)</a><br><a action=\"bypass -h Quest 642_APowerfulPrimevalCreature 8708\">制作卷轴(卡布里欧之手60%)</a><br><a action=\"bypass -h Quest 642_APowerfulPrimevalCreature 8710\">制作卷轴(恶魔结晶60%)</a><br><a action=\"bypass -h Quest 642_APowerfulPrimevalCreature Dinn_K\">现在不想加工</a></body></html>"
# 32105-07a
Dinn_J = "<html><body>丁定：<br>要进行实验的话，需要有1颗古代之卵与150个恐龙活体组织为一组的套件。去击倒<font color=\"LEVEL\">喙嘴龙、暴龙、迅猛龙</font>后，将它们的活体组织来...还有别忘了搜寻恐龙们的栖息地，将<font color=\"LEVEL\">古代之卵</font>拿来吧...</body></html>"
# 32105-08
Dinn_K = "<html><body>丁定：<br>谢谢！<br>那么继续去击倒<font color=\"LEVEL\">喙嘴龙、暴龙、迅猛龙</font>后，收集它们的活体组织来吧。<br>对了，将1颗<font color=\"LEVEL\">古代之卵</font>与150个恐龙活体组织组为一套的话，也可透过实验来加工喔。<br>只要搜寻恐龙们的栖息地就能找得到古代之卵。但是非常危险，可要小心喔。触碰古代之卵的话，<font color=\"LEVEL\">周围的恐龙们为了保护古代之卵，会全部跑来的。古代之卵不像恐龙活体组织一样需要很多，所以请考虑清楚后再做决定吧！</font><br>那么，继续辛苦您了。</body></html>"
# 32105-09
Dinn_L = "<html><body>丁定：<br>是的，我不是说过了吗？尽管去忙您的事情吧。</body></html>"
# 32105-10
Dinn_M = "<html><body>卡拉卡维：<br>用活体组织450个的话，我会按照那个数量支付你合理的酬劳。<br>你想要选择什么呢？<br><a action=\"bypass -h Quest 642_APowerfulPrimevalCreature 1\">换取“制作卷轴-（王朝剑60%）”</a><br><a action=\"bypass -h Quest 642_APowerfulPrimevalCreature 2\">换取“制作卷轴-（王朝之刃60%）”</a><br><a action=\"bypass -h Quest 642_APowerfulPrimevalCreature 3\">换取“制作卷轴-（王朝幻影剑60%）”</a><br><a action=\"bypass -h Quest 642_APowerfulPrimevalCreature 4\">换取“制作卷轴-（王朝弓60%）”</a><br><a action=\"bypass -h Quest 642_APowerfulPrimevalCreature 5\">换取“制作卷轴-（王朝小刀60%）”</a><br><a action=\"bypass -h Quest 642_APowerfulPrimevalCreature 6\">换取“制作卷轴-（王朝长柄战戟60%）”</a><br><a action=\"bypass -h Quest 642_APowerfulPrimevalCreature 7\">换取“制作卷轴-（王朝战锤60%）”</a><br><a action=\"bypass -h Quest 642_APowerfulPrimevalCreature 8\">换取“制作卷轴-（王朝钉锤60%）”</a><br><a action=\"bypass -h Quest 642_APowerfulPrimevalCreature 9\">换取“制作卷轴-（王朝拳套爪60%）”</a></body></html>"
# 32105-11
Dinn_N = "<html><body>丁定：<br>若想得到新的物品，需要有活体组织450个。再去狩猎一些<font color=\"LEVEL\">喙嘴龙、暴龙、迅猛龙</font>后，带回足够的恐龙活体组织吧。</body></html>"

class Quest (JQuest) :

	def __init__(self,id,name,descr):
		JQuest.__init__(self,id,name,descr)
		self.questItemIds = [DINOSAUR_TISSUE, DINOSAUR_EGG]

	def onAdvEvent (self,event,npc,player) :
		htmltext = event
		st = player.getQuestState(qn)
		if not st : return

		count_tissue = st.getQuestItemsCount(DINOSAUR_TISSUE)
		count_egg = st.getQuestItemsCount(DINOSAUR_EGG)
		if event == "Dinn_E" :
			htmltext = Dinn_E
			st.set("cond","1")
			st.setState(State.STARTED)
			st.playSound("ItemSound.quest_accept")
		elif event == "Dinn_H" :
			htmltext = Dinn_H
			st.takeItems(DINOSAUR_TISSUE,-1)
			st.giveItems(57,count_tissue*5000)
		elif event == "Dinn_I" :
			if count_tissue < 150 or count_egg == 0 :
				htmltext = Dinn_J
			elif ALT_RP_100 != 0 :
				#htmltext = st.showHtmlFile("Dinn_I").replace("60%","100%")
				htmltext = Dinn_I
		elif event.isdigit() and int(event) in REWARDS :
			if count_tissue >= 150 and count_egg >= 1 :
				htmltext = Dinn_K
				st.takeItems(DINOSAUR_TISSUE,150)
				st.takeItems(DINOSAUR_EGG,1)
				st.giveItems(57,44000)
				if ALT_RP_100 != 0 :
					st.giveItems(int(event)+1,1)
				else :
					st.giveItems(int(event),1)
			else :
				htmltext = Dinn_J
		elif event == "Dinn_M" :
			if count_tissue >= 450 :
				htmltext = Dinn_M
			else :
				htmltext = Dinn_N
		elif event in REWARDS_W.keys() :
			if count_tissue >= 450 :
				item, amount = REWARDS_W[event]
				st.takeItems(DINOSAUR_TISSUE,450)
				st.rewardItems(item, amount)
				st.playSound("ItemSound.quest_itemget")
				htmltext = Dinn_M
			else :
				htmltext = Dinn_N
		elif event == "Dinn_A" :
			htmltext = Dinn_A
		elif event == "Dinn_B" :
			htmltext = Dinn_B
		elif event == "Dinn_C" :
			htmltext = Dinn_C
		elif event == "Dinn_D" :
			htmltext = Dinn_D
		elif event == "Dinn_E" :
			htmltext = Dinn_E
		elif event == "Dinn_F" :
			htmltext = Dinn_F
		elif event == "Dinn_G" :
			htmltext = Dinn_G
		elif event == "Dinn_H" :
			htmltext = Dinn_H
		elif event == "Dinn_I" :
			htmltext = Dinn_I
		elif event == "Dinn_J" :
			htmltext = Dinn_J
		elif event == "Dinn_K" :
			htmltext = Dinn_K
		elif event == "Dinn_L" :
			htmltext = Dinn_L
		elif event == "Dinn_M" :
			htmltext = Dinn_M
		elif event == "Dinn_N" :
			htmltext = Dinn_N
		return htmltext

	def onTalk (self,npc,player):
		htmltext = "<html><body>目前没有执行任务，或条件不符。</body></html>"
		st = player.getQuestState(qn)
		if not st: return htmltext

		npcId = npc.getNpcId()
		id = st.getState()
		cond = st.getInt("cond")

		count = st.getQuestItemsCount(DINOSAUR_TISSUE)
		if id == State.CREATED :
			if npcId == 32105 and cond == 0 :
				if player.getLevel() >= 75 :
					htmltext = Dinn_B
				else :
					htmltext = Dinn_A
					st.exitQuest(1)
		elif id == State.STARTED :
			if npcId == 32105 and cond == 1 :
				if count == 0 :
					htmltext = Dinn_F
				else :
					htmltext = Dinn_G
		return htmltext

	def onKill (self, npc, player,isPet):
		partyMember = self.getRandomPartyMember(player,"1")
		if not partyMember: return
		st = partyMember.getQuestState(qn)
		if st :
			if st.getState() == State.STARTED :
				npcId = npc.getNpcId()
				cond = st.getInt("cond")
				count = st.getQuestItemsCount(DINOSAUR_TISSUE)
				if cond == 1 :
					if npcId == 18344 :
						itemId = DINOSAUR_EGG
						chance = EGG_DROP_CHANCE*Config.RATE_QUEST_DROP
						numItems, chance = divmod(chance,100)
					else :
						itemId = DINOSAUR_TISSUE
						chance = TISSUE_DROP_CHANCE*Config.RATE_QUEST_DROP
						numItems, chance = divmod(chance,100)
					if self.getRandom(100) < chance : 
						numItems += 1
					if numItems :
						if int(count + numItems) and itemId == DINOSAUR_TISSUE :
							st.playSound("ItemSound.quest_itemget")
						st.giveItems(itemId,int(numItems))
		return

QUEST		= Quest(642,qn,"有关太古强力生物的研究")

QUEST.addStartNpc(32105)

QUEST.addTalkId(32105)

for mob in DINOSAURS :
   QUEST.addKillId(mob)